home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Please don't shoot me (newbie question)
- Date: Thu, 18 Apr 1996 12:29:32 -0400
- Organization: Datalytics, Inc
- Message-ID: <31766DEC.4EED@datalytics.com>
- References: <4l0puc$oa9@interport.net>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Tom Metzger wrote:
- >
- > I just started lurking here, so please don't shoot me if this has been asked
- > a hundred times before, but....
- >
- > Can someone explain to me, in clear terms, what the difference is between
- > C and C++ ? Everytime I've asked someone, the answer is so cryptic, it's
- > not funny.
- >
-
- C++ is a better C than C. That, too, is cryptic, I know, but
- let me explain. C++ offers stricter type checking. In other
- words, the C++ compiler requires parameters to match functions,
- etc. C can let more things slide.
-
- C++ offers function overloading. This means that you can have
- more than one function with the same name. So long as they take
- different parameters, they are different functions. This means
- you can have several versions of Read or Write, for example,
- that each take different parameters.
-
- C++ offers automatic initialization and cleanup of structs (C++
- classes are structs with private access by default).
- Initialization is done through constructors; cleanup through
- destructors. When you create a struct (or class object), the
- compiler invokes the corresponding constructor, if any. When it
- goes out of scope, the compiler invokes the destructor. This
- allows you to manage various resources (like file handles, heap
- memory allocations, etc.) within the struct (class).
-
- C++ offers encapsulation of data and functions. Functions that
- operate on common data can be encapsulated in a class (or
- struct, if you want). This makes clear that they class data
- (data members) are shared among those functions, but are not
- (should not be) available to others (except through those
- functions). This is a powerful thing: it keeps you from
- creating lots of globals that any number of functions can use
- whenever and however they like. By placing functions that
- operate on the same data in a class (struct) declaration, you
- highlight that they share data among them. This heightens your
- awareness of their interrelationship.
-
- C++ offers many other things, including polymorphism, templates,
- runtime type identification, exceptions, etc. There is much to
- the C++ beast.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-